﻿// -----------------------------------------------------------------------
// <copyright file="StringValidation.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace RauteAdministarion.Classes
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Controls;
    using System.Globalization;
    using System.Text.RegularExpressions;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    class StringValidationRule : ValidationRule
    {
        public string Pattern { get; set; }

        public StringValidationRule()
            : this("\\w{1,20}")
        {
        }

        public StringValidationRule(string pattern)
        {
            this.Pattern = pattern;
        }

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (value != null && Regex.IsMatch(value.ToString(), this.Pattern))
            {
                return new ValidationResult(true, null);
            }
            else if (value == null || string.IsNullOrEmpty(value.ToString()))
            {
                return new ValidationResult(false, "please enter some string");
            }
            return new ValidationResult(false, "value not in the correct format");
        }
    }
}
